<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="姓名" prop="empName">
        <el-input
          v-model="queryParams.empName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="cardId">
        <el-input
          v-model="queryParams.cardId"
          placeholder="请输入身份证号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人员类型" prop="empType">
        <el-select v-model="queryParams.empType" placeholder="请选择人员类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="外包业务类型" prop="outcompanyServType" label-width="100px">
        <el-select v-model="queryParams.outcompanyServType" placeholder="外包业务类型" clearable size="small" >
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="单元负责人" prop="unitLeader" label-width="100px">
        <el-input
          v-model="queryParams.unitLeader"
          placeholder="单元负责人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hr:EMPLOY:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hr:EMPLOY:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hr:EMPLOY:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hr:EMPLOY:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="EMPLOYList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="操作模式" align="center" prop="operModeName" />
      <el-table-column label="人员编号" align="center" prop="empId" />
      <el-table-column label="姓名" align="center" prop="empName" />
      <el-table-column label="身份证号码" align="center" prop="cardId" />
      <el-table-column label="性别" align="center" prop="empSex" />
      <el-table-column label="人员类型" align="center" prop="empType" />
      <el-table-column label="出生日期" align="center" prop="birthDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="政治面貌" align="center" prop="politicalLandscape" />
      <el-table-column label="国籍" align="center" prop="citizenship" />
      <el-table-column label="电子邮件地址" align="center" prop="emailAdress" />
      <el-table-column label="户口类型" align="center" prop="accountType" />
      <el-table-column label="户口所在地" align="center" prop="accountAdress" />
      <el-table-column label="民族" align="center" prop="nation" />
      <el-table-column label="移居国外者" align="center" prop="emigrants" />
      <el-table-column label="进入外包单位日期" align="center" prop="enterOutcompanyDate" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enterOutcompanyDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="从事联通业务开始日期(不可修改)" align="center" prop="enterChinauniomDate" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enterChinauniomDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="分配开始时间" align="center" prop="distributeDate" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.distributeDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属外包公司" align="center" prop="companyName" />
      <el-table-column label="所属外包合同编号" align="center" prop="contractId" />
      <el-table-column label="组织名称" align="center" prop="organizeName" />
      <el-table-column label="从事外包业务类型" align="center" prop="outcompanyServType" />
      <el-table-column label="从事联通服务途径" align="center" prop="serviceChannl" />
      <el-table-column label="原人员编号" align="center" prop="oriEmpId" />
      <el-table-column label="纳税地" align="center" prop="taxPlace" />
      <el-table-column label="社保缴纳地" align="center" prop="sociaSecurityPlace" />
      <el-table-column label="岗位序列" align="center" prop="postSequence" />
      <el-table-column label="岗位分类" align="center" prop="postClass" />
      <el-table-column label="参考岗级" align="center" prop="referenceLevel" />
      <el-table-column label="考核信息" align="center" prop="checkInfo" />
      <el-table-column label="划小单元负责人" align="center" prop="unitLeader" />
      <el-table-column label="核算到划小单元" align="center" prop="accountUnit" />
      <el-table-column label="备用1" align="center" prop="reserved1" />
      <el-table-column label="备用2" align="center" prop="reserved2" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hr:EMPLOY:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hr:EMPLOY:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <!--          <el-checkbox v-model="upload.updateSupport"/>-->
          <!--          是否更新已经存在的员工数据-->
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改人员信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="操作模式" prop="operModeName">
          <el-input v-model="form.operModeName" placeholder="请输入操作模式" />
        </el-form-item>
        <el-form-item label="姓名" prop="empName">
          <el-input v-model="form.empName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="cardId">
          <el-input v-model="form.cardId" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="性别">
          <el-select v-model="form.empSex" placeholder="请选择性别">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="人员类型">
          <el-select v-model="form.empType" placeholder="请选择人员类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthDate">
          <el-input v-model="form.birthDate" placeholder="请输入出生日期" />
        </el-form-item>
        <el-form-item label="政治面貌" prop="politicalLandscape">
          <el-input v-model="form.politicalLandscape" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="国籍" prop="citizenship">
          <el-input v-model="form.citizenship" placeholder="请输入国籍" />
        </el-form-item>
        <el-form-item label="电子邮件地址" prop="emailAdress">
          <el-input v-model="form.emailAdress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="户口类型">
          <el-select v-model="form.accountType" placeholder="请选择户口类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="户口所在地" prop="accountAdress">
          <el-input v-model="form.accountAdress" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="民族" prop="nation">
          <el-input v-model="form.nation" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="移居国外者" prop="emigrants">
          <el-input v-model="form.emigrants" placeholder="请输入移居国外者" />
        </el-form-item>
        <el-form-item label="进入外包单位日期" prop="enterOutcompanyDate">
          <el-input v-model="form.enterOutcompanyDate" placeholder="请输入进入外包单位日期" />
        </el-form-item>
        <el-form-item label="从事联通业务开始日期(不可修改)" prop="enterChinauniomDate">
          <el-input v-model="form.enterChinauniomDate" placeholder="请输入从事联通业务开始日期(不可修改)" />
        </el-form-item>
        <el-form-item label="分配开始时间" prop="distributeDate">
          <el-input v-model="form.distributeDate" placeholder="请输入分配开始时间" />
        </el-form-item>
        <el-form-item label="所属外包公司" prop="companyName">
          <el-input v-model="form.companyName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所属外包合同编号" prop="contractId">
          <el-input v-model="form.contractId" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="组织名称" prop="organizeName">
          <el-input v-model="form.organizeName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="从事外包业务类型">
          <el-select v-model="form.outcompanyServType" placeholder="请选择从事外包业务类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="从事联通服务途径" prop="serviceChannl">
          <el-input v-model="form.serviceChannl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="原人员编号" prop="oriEmpId">
          <el-input v-model="form.oriEmpId" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="纳税地" prop="taxPlace">
          <el-input v-model="form.taxPlace" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="社保缴纳地" prop="sociaSecurityPlace">
          <el-input v-model="form.sociaSecurityPlace" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="岗位序列" prop="postSequence">
          <el-input v-model="form.postSequence" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="岗位分类" prop="postClass">
          <el-input v-model="form.postClass" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="参考岗级" prop="referenceLevel">
          <el-input v-model="form.referenceLevel" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="考核信息" prop="checkInfo">
          <el-input v-model="form.checkInfo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="划小单元负责人" prop="unitLeader">
          <el-input v-model="form.unitLeader" placeholder="请输入划小单元负责人" />
        </el-form-item>
        <el-form-item label="核算到划小单元" prop="accountUnit">
          <el-input v-model="form.accountUnit" placeholder="请输入核算到划小单元" />
        </el-form-item>
        <el-form-item label="备用1" prop="reserved1">
          <el-input v-model="form.reserved1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备用2" prop="reserved2">
          <el-input v-model="form.reserved2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEMPLOY, getEMPLOY, delEMPLOY, addEMPLOY, updateEMPLOY, exportEMPLOY,importTemplate } from "@/api/hr/EMPLOY";
import { getToken } from "@/utils/auth";

export default {
  name: "EMPLOY",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 人员信息管理表格数据
      EMPLOYList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        operModeName: undefined,
        empName: undefined,
        cardId: undefined,
        empSex: undefined,
        empType: undefined,
        birthDate: undefined,
        politicalLandscape: undefined,
        citizenship: undefined,
        emailAdress: undefined,
        accountType: undefined,
        accountAdress: undefined,
        nation: undefined,
        emigrants: undefined,
        enterOutcompanyDate: undefined,
        enterChinauniomDate: undefined,
        distributeDate: undefined,
        companyName: undefined,
        contractId: undefined,
        organizeName: undefined,
        outcompanyServType: undefined,
        serviceChannl: undefined,
        oriEmpId: undefined,
        taxPlace: undefined,
        sociaSecurityPlace: undefined,
        postSequence: undefined,
        postClass: undefined,
        referenceLevel: undefined,
        checkInfo: undefined,
        unitLeader: undefined,
        accountUnit: undefined,
        reserved1: undefined,
        reserved2: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        empName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        cardId: [
          { required: true, message: "身份证号码不能为空", trigger: "blur" }
        ],
      },
        upload: {
            // 是否显示弹出层（用户导入）
            open: false,
            // 弹出层标题（用户导入）
            title: "",
            // 是否禁用上传
            isUploading: false,
            // 是否更新已经存在的用户数据
            updateSupport: 0,
            // 设置上传的请求头部
            headers: {Authorization: "Bearer " + getToken()},
            // 上传的地址
            url: process.env.VUE_APP_BASE_API + "/hr/EMPLOY/importData"
        },
    };
  },
  created() {
    this.getList();
  },
  methods: {
      /** 导入按钮操作 */
      handleImport() {
          this.upload.title = "用户导入";
          this.upload.open = true;
      },
    /** 查询人员信息管理列表 */
    getList() {
      this.loading = true;
      listEMPLOY(this.queryParams).then(response => {
        this.EMPLOYList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        operModeName: undefined,
        empId: undefined,
        empName: undefined,
        cardId: undefined,
        empSex: undefined,
        empType: undefined,
        birthDate: undefined,
        politicalLandscape: undefined,
        citizenship: undefined,
        emailAdress: undefined,
        accountType: undefined,
        accountAdress: undefined,
        nation: undefined,
        emigrants: undefined,
        enterOutcompanyDate: undefined,
        enterChinauniomDate: undefined,
        distributeDate: undefined,
        companyName: undefined,
        contractId: undefined,
        organizeName: undefined,
        outcompanyServType: undefined,
        serviceChannl: undefined,
        oriEmpId: undefined,
        taxPlace: undefined,
        sociaSecurityPlace: undefined,
        postSequence: undefined,
        postClass: undefined,
        referenceLevel: undefined,
        checkInfo: undefined,
        unitLeader: undefined,
        accountUnit: undefined,
        reserved1: undefined,
        reserved2: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.empId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加人员信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const empId = row.empId || this.ids
      getEMPLOY(empId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改人员信息管理";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.empId != undefined) {
            updateEMPLOY(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addEMPLOY(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const empIds = row.empId || this.ids;
      this.$confirm('是否确认删除人员信息管理编号为"' + empIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delEMPLOY(empIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有人员信息管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportEMPLOY(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
      /** 下载模板操作 */
      importTemplate() {
          importTemplate().then(response => {
              this.download(response.msg);
          });
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
          this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
          this.upload.open = false;
          this.upload.isUploading = false;
          this.$refs.upload.clearFiles();
          this.$alert(response.msg, "导入结果", {dangerouslyUseHTMLString: true});
          this.getList();
      },
      // 提交上传文件
      submitFileForm() {
          debugger
          this.$refs.upload.submit();
      }
  }
};
</script>
